import React, {Component} from 'react';
import {PageContainer} from "@ant-design/pro-components";
import {message, Space, Table, Tag, Text, Typography} from 'antd';
import type {ColumnsType} from 'antd/lib/table';
import {Button} from 'antd';
import {Link} from "umi";
import {request} from "umi";
import {getUserInfo, MergeMenu} from "@/utils/format";
import {FillProgress, QuerySubMenus} from "@/services/School/SchoolMenuApi";
import {ServerMessages} from "@/services/ServerMessages";
import {ShowError} from "@/utils/format";

class GraduateEmployment extends Component {
  state = {
    loading: true,
    data: []
  }

  fillMap = {
    '1_1': '/disci-cons/progress',
    '2_1': '/cultivate-talents/education',
    '2_2': '/cultivate-talents/progress',
    '2_3': '/cultivate-talents/graduate-employment',
    '2_4': '/cultivate-talents/international-contacts',
    '3_1': '/teacher-team/teacher-morality',
    '3_2': '/teacher-team/major-teacher',
    '3_3': '/teacher-team/international-level',
    '4_1': '/research/research-innovate',
    '4_2': '/research/research-platform',
    '4_3': '/research/international-influence',
    '5_1': '/social-services/social-services',
    '5_2': '/social-services/social-support',
    '5_4': '/social-services/services-social',
  }

  linkTo = (to: string) => {
    return this.fillMap[to.substring(0, 3)]
  }

  componentDidMount() {

    // let data = [
    //   {
    //     key: '2_3_1',
    //     name: '年度授予学士、硕士、博士学位情况',
    //     circle: '一年一次',
    //     target: '学科填报',
    //     flag: 1,
    //     to: '/cultivate-talents/graduate-employment/degree-counts',
    //   },
    //   {
    //     key: '2_3_2',
    //     name: '学科领域突出贡献者情况',
    //     circle: '一年一次',
    //     target: '学科填报',
    //     flag: 1,
    //     to: '/cultivate-talents/graduate-employment/discipline-pioneer',
    //   },
    // ]
    // 将 response 的 flag 映射到 data 的 flag 上
    // this.setState({loading: false, data})

    // QuerySubMenus('2_3').then(response => {
    //   console.log("@返回数据", response)
    //   data = MergeMenu(data, response)
    //   this.setState({loading: false, data})
    // }, () => {
    //   ShowError(ServerMessages.error_message)
    // })

    FillProgress().then(response => {
      console.log("@返回值", response)
      //   console.log("@返回数据", response)
      let data = []
      for (let i = 0; i < response.tables.length; i++) {
        data.push({
          key: response.tables[i].id,
          name: response.tables[i].name,
          circle: response.tables[i].cicle,
          target: '学科填报',
          flag: 1,
          is_filled: response.tables[i].is_filled,
          is_period: response.tables[i].is_period,
          to: '/disci-cons/progress',
        })
      }
      console.log(data)
      this.setState({loading: false, data: data})
    }, () => {
      ShowError(ServerMessages.error_message)
      this.setState({loading: false})
    })

  }

  render() {

    const columns = [
      {
        title: '监测点',
        dataIndex: 'name',
        key: 'name',
        render: text => <b>{text}</b>,
      },
      {
        title: '填报周期',
        dataIndex: 'circle',
        key: 'circle',
        render: text => <b>{text}</b>
      },
      {
        title: '填报对象',
        dataIndex: 'target',
        key: 'target',
      },
      {
        title: '进度',
        key: 'action',
        render: (_, record) => (
          <Space size="middle">
            {record.is_period === 0 && (
              <Button type="primary" disabled>未到填报时间</Button>
            )}
            {record.is_period === 1 && record.is_filled === 1 && (
              <>
                <Button type="primary" disabled>已填报</Button>
              </>
            )}
            {record.is_period === 1 && record.is_filled === 0 && (
              <Link to={this.linkTo(record.key)}><Button type="primary">去填报</Button></Link>
            )}
          </Space>
        ),
      },
    ];

    return (
      <PageContainer
        header={{
        title: '学科填报总览',
        breadcrumb: {},
      }}
      >
        <Table loading={this.state.loading} columns={columns} dataSource={this.state.data}
               pagination={{pageSize: 100}}/>
      </PageContainer>
    );
  }
}

export default GraduateEmployment;
